<!DOCTYPE html>
<html>
<head>
    <title>Parallel Plate Capacitor Diagram</title>
    <style>
        body {
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }
        canvas {
            border: 1px solid #ccc;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <canvas id="physics-diagram" width="500" height="500"></canvas>
    <script>
        const canvas = document.getElementById('physics-diagram');
        const ctx = canvas.getContext('2d');

        // --- Drawing Parameters ---
        const plateWidth = 300;
        const plateHeight = 20;
        const startX = (canvas.width - plateWidth) / 2;
        const yA = 80;
        const d1_px = 60;
        const d0_px = 80;
        const d2_px = 60;
        
        const yB = yA + plateHeight + d1_px;
        const yC = yB + plateHeight + d0_px;
        const yD = yC + plateHeight + d2_px;
        
        const centerX = startX + plateWidth / 2;
        const arrowHeadSize = 8;
        
        ctx.fillStyle = 'black';
        ctx.strokeStyle = 'black';
        ctx.lineWidth = 1.5;

        // --- Draw Plates ---
        ctx.fillRect(startX, yA, plateWidth, plateHeight); // Plate A
        ctx.fillRect(startX, yB, plateWidth, plateHeight); // Plate B
        ctx.fillRect(startX, yC, plateWidth, plateHeight); // Plate C
        ctx.fillRect(startX, yD, plateWidth, plateHeight); // Plate D

        // --- Draw Plate and Charge Labels ---
        ctx.font = "italic 30px 'Times New Roman'";
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';
        
        ctx.fillText('A', startX - 40, yA + plateHeight / 2);
        ctx.fillText('B', startX - 40, yB + plateHeight / 2);
        ctx.fillText('C', startX - 40, yC + plateHeight / 2);
        ctx.fillText('D', startX - 40, yD + plateHeight / 2);
        
        ctx.font = "italic 24px 'Times New Roman'";
        ctx.textAlign = 'left';
        ctx.fillText('q', startX + plateWidth + 20, yB + plateHeight / 2);

        // --- Draw Distance Indicators ---
        
        // Helper function for double-headed arrow
        function drawDoubleArrow(x, y_start, y_end) {
            ctx.beginPath();
            ctx.moveTo(x, y_start);
            ctx.lineTo(x, y_end);
            // Top arrowhead
            ctx.moveTo(x, y_start);
            ctx.lineTo(x - arrowHeadSize / 2, y_start + arrowHeadSize);
            ctx.moveTo(x, y_start);
            ctx.lineTo(x + arrowHeadSize / 2, y_start + arrowHeadSize);
            // Bottom arrowhead
            ctx.moveTo(x, y_end);
            ctx.lineTo(x - arrowHeadSize / 2, y_end - arrowHeadSize);
            ctx.moveTo(x, y_end);
            ctx.lineTo(x + arrowHeadSize / 2, y_end - arrowHeadSize);
            ctx.stroke();
        }

        // Distance d1
        const x_arrow = centerX + 60;
        const y1_start = yA + plateHeight;
        const y1_end = yB;
        drawDoubleArrow(x_arrow, y1_start, y1_end);
        ctx.font = "italic 24px 'Times New Roman'";
        ctx.textAlign = 'left';
        ctx.fillText('d\u2081', x_arrow + 15, (y1_start + y1_end) / 2);

        // Distance d0 (dashed line)
        const x_dash = centerX;
        const y0_start = yB + plateHeight;
        const y0_end = yC;
        ctx.beginPath();
        ctx.setLineDash([5, 5]);
        ctx.moveTo(x_dash, y0_start);
        ctx.lineTo(x_dash, y0_end);
        ctx.stroke();
        ctx.setLineDash([]); // Reset to solid line
        ctx.fillText('d\u2080', x_dash + 15, (y0_start + y0_end) / 2);

        // Distance d2
        const y2_start = yC + plateHeight;
        const y2_end = yD;
        drawDoubleArrow(x_arrow, y2_start, y2_end);
        ctx.fillText('d\u2082', x_arrow + 15, (y2_start + y2_end) / 2);
        
        // --- Draw Caption ---
        ctx.font = "24px 'SimSun'";
        ctx.textAlign = 'center';
        ctx.fillText('图 1', centerX, yD + plateHeight + 60);

    </script>
</body>
</html>